import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';
import { ApiProvider } from '../../providers/api/api'
import { Md5 } from 'ts-md5/dist/md5';

/**
 * Generated class for the UserServicePicPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
    selector: 'page-user-service-pic',
    templateUrl: 'user-service-pic.html',
})
export class UserServicePicPage {
    public uid: any;
    public resData: any = {};
    public url: any;


    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public viewCtrl: ViewController,
        public Api: ApiProvider ) {

    }

    ionViewDidEnter() {
        this.PostData();
    }

    dismiss() {
        this.viewCtrl.dismiss();
    }

    PostData(){
        let timeStamp = (new Date()).getTime();
        this.Api.qrcode({
            times: timeStamp,
            token: Md5.hashStr('HalfPriceMall' + timeStamp),
        }).then(res=>{
            this.resData = res;
            if ( this.resData.code == 1 ) {
                this.url = this.resData.kfcode;
            }
        })
    }

}
